home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 January / Disc 3 / Amethyst.iso / live / usr / share / vim / vim60 / plugin / netrw.vim < prev    next >
Encoding:
Text File  |  2002-06-19  |  21.7 KB  |  665 lines

  1. " netrw.vim: (global plugin) Handles file transfer across a network
  2. " Last Change:    September 14, 2001
  3. " Maintainer:    Charles E. Campbell, Jr. PhD   <cec@NgrOyphSon.gPsfAc.nMasa.gov>
  4. " Version:    2.15
  5.  
  6. " Credits:
  7. "  Vim editor   by Bram Moolenaar (Thanks, Bram!)
  8. "  rcp, ftp support by C Campbell <cec@NgrOyphSon.gPsfAc.nMasa.gov>
  9. "  scp  support by raf            <raf@comdyn.com.au>
  10. "  http support by Bram Moolenaar <bram@moolenaar.net>
  11. "  inputsecret(), BufReadCmd, BufWriteCmd contributed by C Campbell
  12.  
  13. " Debugging:
  14. "    If you'd like to try the built-in debugging commands...
  15. ""        :g/DBG/s/^"//        to activate    debugging
  16. ""        :g/DBG/s/^/"/        to de-activate    debugging
  17. ""    You'll need to get <Decho.vim> and put it into your <.vim/plugin>
  18. ""    (or <vimfiles\plugin> for Windows).  Its available at
  19. ""    http://www.erols.com/astronaut/vim/vimscript/Decho.vim
  20.  
  21. " Options:
  22. "    let g:netrw_ftp = 1
  23. "      If you're having trouble with ftp-.netrc file (ie. you don't
  24. "      have a <.netrc> file) then you may wish to try putting the
  25. "      statement above in your <.vimrc> file.
  26. "
  27. "    User Function NetReadFixup(tmpfile)
  28. "      If your ftp has an obnoxious habit of prepending/appending
  29. "      lines to stuff it reads (for example, one chap had a misconfigured
  30. "      ftp with kerberos which kept complaining with AUTH and KERBEROS
  31. "      messages) you may write your own function NetReadFixup to fix
  32. "      up the file.
  33.  
  34. " Reading:
  35. " :Nread ?                give help
  36. " :Nread "machine:file"            uses rcp
  37. " :Nread "machine file"            uses ftp with <.netrc>
  38. " :Nread "machine id password file"    uses ftp
  39. " :Nread "ftp://machine[#port]/file"    uses ftp  (autodetects <.netrc>)
  40. " :Nread "http://[user@]machine/file"    uses http (wget)
  41. " :Nread "rcp://machine/file"        uses rcp
  42. " :Nread "scp://[user@]machine/file"    uses scp
  43.  
  44. " Writing:
  45. " :Nwrite ?                give help
  46. " :Nwrite "machine:file"        uses rcp
  47. " :Nwrite "machine file"        uses ftp with <.netrc>
  48. " :Nwrite "machine id password file"    uses ftp
  49. " :Nwrite "ftp://machine[#port]/file"    uses ftp  (autodetects <.netrc>)
  50. " :Nwrite "rcp://machine/file"        uses rcp
  51. " :Nwrite "scp://[user@]machine/file"    uses scp
  52. " http: not supported!
  53.  
  54. " User And Password Changing:
  55. "  Attempts to use ftp will prompt you for a user-id and a password.
  56. "  These will be saved in g:netrw_uid and g:netrw_passwd
  57. "  Subsequent uses of ftp will re-use those.  If you need to use
  58. "  a different user id and/or password, you'll want to
  59. "  call NetUserPass() first.
  60.  
  61. "    :NetUserPass [uid [password]]        -- prompts as needed
  62. "    :call NetUserPass()            -- prompts for uid and password
  63. "    :call NetUserPass("uid")        -- prompts for password
  64. "    :call NetUserPass("uid","password")    -- sets global uid and password
  65.  
  66. " Variables:
  67. "    b:netrw_lastfile : last file Network-read/written retained on
  68. "               a per-buffer basis (supports bare :Nw )
  69. "    b:netrw_line     : during Nw/NetWrite, holds current line   number
  70. "    b:netrw_col     : during Nw/NetWrite, holds current column number
  71. "               b:netrw_line and b:netrw_col are used to restore
  72. "               the cursor position on writes
  73. "
  74. "    g:netrw_uid     : (ftp) user id,      retained on a per-session basis
  75. "    g:netrw_passwd     : (ftp) password,     retained on a per-session basis
  76. "    g:netrw_ftp     : if it doesn't exist, use default ftp (uid password)
  77. "             =0 : use default ftp (uid password)
  78. "             =1 : use alternate ftp method
  79.  
  80. "  But be doers of the word, and not only hearers, deluding your own selves
  81. "  (James1:22 RSV)
  82. " =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  83.  
  84. " Exit quickly when already loaded or when 'compatible' is set.
  85. if exists("loaded_netrw") || &cp
  86.   finish
  87. endif
  88. let loaded_netrw = 1
  89. let s:save_cpo = &cpo
  90. set cpo&vim
  91.  
  92. " Vimrc Support:
  93. " Auto-detection for ftp://*, rcp://*, scp://*, and http://*
  94. " Should make file transfers across networks transparent.  Currently I haven't
  95. " supported appends.  Hey, gotta leave something for <netrw.vim> version 3!
  96. if version >= 600
  97.  augroup Network
  98.   au!
  99.   au BufReadCmd        ftp://*,rcp://*,scp://*,http://* exe "Nread 0r " . expand("<afile>") | exe "doau BufReadPost " . expand("<afile>")
  100.   au FileReadCmd    ftp://*,rcp://*,scp://*,http://* exe "Nread "     . expand("<afile>") | exe "doau BufReadPost " . expand("<afile>")
  101.   au BufWriteCmd    ftp://*,rcp://*,scp://*         exe "Nwrite "     . expand("<afile>")
  102.  augroup END
  103. endif
  104.  
  105. " ------------------------------------------------------------------------
  106.  
  107. " Commands: :Nread, :Nwrite, and :NetUserPass
  108. :com -nargs=* Nread call s:NetRead(<f-args>)
  109. :com -range=% -nargs=* Nwrite let b:netrw_line=line(".")|let b:netrw_col=col(".")-1 | <line1>,<line2>call s:NetWrite(<f-args>)
  110. :com -nargs=* NetUserPass call NetUserPass(<f-args>)
  111.  
  112. " ------------------------------------------------------------------------
  113.  
  114. " NetRead: responsible for reading a file over the net
  115. function! s:NetRead(...)
  116. "    Decho "DBG: NetRead(a:1<".a:1.">) {"
  117.  
  118.  " save options
  119.  call <SID>NetOptionSave()
  120.  
  121.  " get temporary file
  122.  let tmpfile = tempname()
  123. "    Decho "DBG: tmpfile<".tmpfile.">"
  124.  
  125.  " Special Exception: if a file is named "0r", then
  126.  "              "0r" will be used to read the
  127.  "              following files instead of "r"
  128.  if    a:0 == 0
  129.   let readcmd= "r"
  130.   let ichoice= 0
  131.  elseif a:1 == "0r"
  132.   let readcmd = "0r"
  133.   let ichoice = 2
  134.  else
  135.   let readcmd = "r"
  136.   let ichoice = 1
  137.  endif
  138.  
  139.  while ichoice <= a:0
  140.  
  141.   " attempt to repeat with previous host-file-etc
  142.   if exists("b:netrw_lastfile") && a:0 == 0
  143. "    Decho "DBG: using b:netrw_lastfile<" . b:netrw_lastfile . ">"
  144.    let choice = b:netrw_lastfile
  145.    let ichoice= ichoice + 1
  146.  
  147.   else
  148.    exe "let choice= a:" . ichoice
  149. "    Decho "DBG: NetRead1: choice<" . choice . ">"
  150.  
  151.    " Reconstruct Choice if choice starts with '"'
  152.    if match(choice,"?") == 0
  153.     echo "NetRead Usage:"
  154.     echo ":Nread machine:file                  uses rcp"
  155.     echo ':Nread "machine file"                uses ftp with <.netrc>'
  156.     echo ':Nread "machine id password file"    uses ftp'
  157.     echo ':Nread ftp://machine[#port]/file     uses ftp  (autodetects <.netrc>)'
  158.     echo ":Nread http://[user@]machine/file    uses http (wget)"
  159.     echo ":Nread rcp://machine/file            uses rcp"
  160.     echo ":Nread scp://[user@]machine/file     uses scp"
  161.     break
  162.    elseif match(choice,"^\"") != -1
  163. "    Decho "DBG: reconstructing choice"
  164.     if match(choice,"\"$") != -1
  165.      " case "..."
  166.      let choice=strpart(choice,1,strlen(choice)-2)
  167.     else
  168.       "  case "... ... ..."
  169.      let choice  = strpart(choice,1,strlen(choice)-1)
  170.      let wholechoice = ""
  171.  
  172.      while match(choice,"\"$") == -1
  173.       let wholechoice = wholechoice . " " . choice
  174.       let ichoice     = ichoice + 1
  175.       exe "let choice= a:" . ichoice
  176.      endwhile
  177.      let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
  178.     endif
  179.    endif
  180.   endif
  181. "    Decho "DBG: NetRead2: choice<" . choice . ">"
  182.   let ichoice= ichoice + 1
  183.  
  184.   " fix up windows urls
  185.   if has("win32")
  186. "    Decho "DBG: fixing up windows url"
  187.    let choice = substitute(choice,'\\','/','ge')
  188.   endif
  189.  
  190.   " Determine method of read (ftp, rcp, etc)
  191.   call s:NetMethod(choice)
  192.  
  193.   " Perform Read
  194.   if  b:netrw_method == 1 " read with rcp
  195. "    Decho "DBG:read via rcp (method #1)"
  196.    exe "!rcp " . g:netrw_machine . ":" . b:netrw_fname . " " . tmpfile
  197.    let result = s:NetGetFile(readcmd, tmpfile)
  198.    let b:netrw_lastfile = choice
  199.  
  200.   elseif b:netrw_method  == 2        " read with ftp + <.netrc>
  201. "    Decho "DBG: read via ftp+.netrc (method #2)\n"
  202.    exe "norm! mzoascii\<cr>get ".b:netrw_fname." ".tmpfile."\<esc>"
  203.    exe "'z+1,.!ftp -i " . g:netrw_machine
  204.    let result = s:NetGetFile(readcmd, tmpfile)
  205.    let b:netrw_lastfile = choice
  206.  
  207.   elseif b:netrw_method == 3        " read with ftp + machine, id, passwd, and fname
  208. "    Decho "DBG: read via ftp+mipf (method #3)"
  209.  
  210.    " Seems to depend on the machine.  Dunno how to choose...
  211.    if exists("g:netrw_ftp")
  212.     if g:netrw_ftp == 1
  213. "    Decho 'DBG: g:netrw_ftp is 1'
  214.      exe "norm! mzoopen ".g:netrw_machine." ".g:netrw_port."\<cr>".g:netrw_uid."\<cr>".g:netrw_passwd."\<cr>ascii\<cr>get ".b:netrw_fname." ".tmpfile."\<esc>"
  215.     else    " same as default where g:netrw_ftp doesn't exist
  216. "    Decho 'DBG: g:netrw_ftp is 0'
  217.      exe "norm! mzoopen ".g:netrw_machine." ".g:netrw_port."\<cr>user ".g:netrw_uid." ".g:netrw_passwd."\<cr>ascii\<cr>get ".b:netrw_fname." ".tmpfile."\<esc>"
  218.     endif
  219.    else
  220. "    Decho 'DBG: g:netrw_ftp does not exist'
  221. "    Decho "DBG: norm! mzoopen ".g:netrw_machine." ".g:netrw_port."\<cr>user ".g:netrw_uid." ".g:netrw_passwd."\<cr>ascii\<cr>get ".b:netrw_fname." ".tmpfile."\<esc>"
  222.     exe "norm! mzoopen ".g:netrw_machine." ".g:netrw_port."\<cr>user ".g:netrw_uid." ".g:netrw_passwd."\<cr>ascii\<cr>get ".b:netrw_fname." ".tmpfile."\<esc>"
  223.    endif
  224.  
  225.    if has("win95")
  226. "    Decho 'DBG: win95 ftp'
  227.     exe "norm! o\<esc>my'zj"
  228.     exe ".,'y-1!ftp -i -n"
  229.     " the ftp on Win95 puts four lines of trash at the end
  230.     " which the following blots out.  Does Win-NT/98/2000 do the same???
  231.     exe "'y-3,'yd"
  232.    else
  233.     " ordinary ftp
  234.     " -i       : turns off interactive prompting from ftp
  235.     " -n  unix : DON'T use <.netrc>, even though it exists
  236.     " -n  win32: quit being obnoxious about password
  237. "    Decho 'DBG: non-Win95 ftp'
  238.     exe "'z+1,.!ftp -i -n"
  239.     if exists("'z")
  240.      norm! 'z
  241.     endif
  242.    endif
  243.    let result = s:NetGetFile(readcmd, tmpfile)
  244.  
  245.    " save choice/id/password for future use
  246.    let b:netrw_lastfile = choice
  247.  
  248.   elseif     b:netrw_method  == 4    " read with scp
  249. "    Decho "DBG: read via scp (method #4)"
  250.    exe "!scp " . g:netrw_machine . ":" . b:netrw_fname . " " . tmpfile
  251.    let result = s:NetGetFile(readcmd, tmpfile)
  252.    let b:netrw_lastfile = choice
  253.  
  254.   elseif     b:netrw_method  == 5    " read with http (wget)
  255. "    Decho "DBG: read via http (method #5)"
  256.    if match(b:netrw_fname,"#") == -1
  257.     exe "!wget http://" . g:netrw_machine . "/" . b:netrw_fname . " -O " . tmpfile
  258.     let result = s:NetGetFile(readcmd, tmpfile)
  259.    else
  260.     let netrw_html= substitute(b:netrw_fname,"#.*$","","")
  261.     let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
  262.     exe "!wget http://" . g:netrw_machine . "/" . netrw_html . " -O " . tmpfile
  263.     let result = s:NetGetFile(readcmd, tmpfile)
  264.     exe 'norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"'
  265.    endif
  266.    set ft=html
  267.    redraw!
  268.    let b:netrw_lastfile = choice
  269.  
  270.   else " Complain
  271.    echo "***warning*** unable to comply with your request<" . choice . ">"
  272.   endif
  273.  endwhile
  274.  
  275.  " cleanup
  276. "    Decho "DBG NetRead: cleanup"
  277.  if exists("b:netrw_method")
  278.   unlet b:netrw_method
  279.   unlet g:netrw_machine
  280.   unlet b:netrw_fname
  281.  endif
  282.  call s:NetOptionRestore()
  283.  
  284. "    Decho "DBG: return NetRead }"
  285. endfunction
  286. " end of NetRead
  287.  
  288. " ------------------------------------------------------------------------
  289.  
  290. " NetGetFile: Function to read file "fname" with command "readcmd".
  291. " Takes care of deleting the last line when the buffer was emtpy.
  292. " Deletes the file "fname".
  293. function! s:NetGetFile(readcmd, fname)
  294.  " User-provided (ie. optiona) fix-it-up command
  295.   if exists("*NetReadFixup")
  296.    call NetReadFixup(a:fname)
  297.   endif
  298. "    Decho "DBG: NetGetFile readcmd<".a:readcmd."> fname<".a:fname.">"
  299.  let dodel = 0
  300.  if line("$") == 1 && getline(1) == ""
  301.   let dodel = 1
  302.  endif
  303.  exe a:readcmd . v:cmdarg . " " . a:fname
  304.  if a:readcmd[0] == '0' && dodel && getline("$") == ""
  305.   $d
  306.   1
  307.  endif
  308.  return delete(a:fname)
  309. endfun
  310.  
  311. " ------------------------------------------------------------------------
  312.  
  313. " NetWrite: responsible for writing a file over the net
  314. function! s:NetWrite(...) range
  315. "    Decho "DBG: NetWrite(a:0=".a:0.") {"
  316.  
  317.  " option handling
  318.  call s:NetOptionSave()
  319.  
  320.  " Get Temporary Filename
  321.  let tmpfile = tempname()
  322.  let tmpFTPfile = tempname()
  323.  
  324.  if a:0 == 0
  325.   let ichoice = 0
  326.  else
  327.   let ichoice = 1
  328.  endif
  329.  
  330.  " write (selected portion of) file to temporary
  331.  exe a:firstline . "," . a:lastline . "w!" . v:cmdarg . " " . tmpfile
  332.  
  333.  while ichoice <= a:0
  334.  
  335.   " attempt to repeat with previous host-file-etc
  336.   if exists("b:netrw_lastfile") && a:0 == 0
  337. "    Decho "DBG: using b:netrw_lastfile<" . b:netrw_lastfile . ">"
  338.    let choice = b:netrw_lastfile
  339.    let ichoice= ichoice + 1
  340.   else
  341.    exe "let choice= a:" . ichoice
  342.  
  343.    " Reconstruct Choice if choice starts with '"'
  344.    if match(choice,"?") == 0
  345.     echo "NetWrite Usage:"
  346.     echo ":Nwrite machine:file                  uses rcp"
  347.     echo ":Nwrite \"machine file\"                uses ftp with <.netrc>"
  348.     echo ":Nwrite \"machine id password file\"    uses ftp"
  349.     echo ":Nwrite ftp://machine[#port]/file          uses ftp  (autodetects <.netrc>)"
  350.     echo ":Nwrite rcp://machine/file          uses rcp"
  351.     echo ":Nwrite scp://[user@]machine/file   uses scp"
  352.     break
  353.  
  354.    elseif match(choice,"^\"") != -1
  355.     if match(choice,"\"$") != -1
  356.       " case "..."
  357.      let choice=strpart(choice,1,strlen(choice)-2)
  358.     else
  359.      "  case "... ... ..."
  360.      let choice     = strpart(choice,1,strlen(choice)-1)
  361.      let wholechoice = ""
  362.  
  363.      while match(choice,"\"$") == -1
  364.       let wholechoice= wholechoice . " " . choice
  365.       let ichoice= ichoice + 1
  366.       exe "let choice= a:" . ichoice
  367.      endwhile
  368.      let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
  369.     endif
  370.    endif
  371.   endif
  372. "    Decho "DBG: choice<" . choice . ">"
  373.   let ichoice= ichoice + 1
  374.  
  375.   " fix up windows urls
  376.   if has("win32")
  377.    let choice= substitute(choice,'\\','/','ge')
  378.   endif
  379.  
  380.   " Determine method of read (ftp, rcp, etc)
  381.   call s:NetMethod(choice)
  382.  
  383.   " Perform Write
  384.   if  b:netrw_method == 1    " write with rcp
  385.    exe "!rcp " . tmpfile . " " . g:netrw_machine . ":" . b:netrw_fname
  386.    let b:netrw_lastfile = choice
  387.  
  388.   elseif b:netrw_method == 2    " write with ftp + <.netrc>
  389.    exe "norm! mzoascii\<cr>put ".tmpfile." ".b:netrw_fname."\<esc>"
  390.    exe "'z+1,.!ftp -i " . g:netrw_machine
  391.    norm! 'z
  392.    let b:netrw_lastfile = choice
  393.  
  394.   elseif b:netrw_method == 3    " write with ftp + machine, id, passwd, and fname
  395.    if exists("g:netrw_ftp")
  396.     if g:netrw_ftp == 1
  397.      exe "norm! mzoopen ".g:netrw_machine." ".g:netrw_port."\<cr>".g:netrw_uid."\<cr>".g:netrw_passwd."\<cr>ascii\<cr>put ".tmpfile." ".b:netrw_fname."\<esc>"
  398.     else
  399.      exe "norm! mzoopen ".g:netrw_machine." ".g:netrw_port."\<cr>"."user ".g:netrw_uid." ".g:netrw_passwd."\<cr>ascii\<cr>put ".tmpfile." ".b:netrw_fname."\<esc>"
  400.     endif
  401.    else
  402.     exe "norm! mzoopen ".g:netrw_machine." ".g:netrw_port."\<cr>"."user ".g:netrw_uid." ".g:netrw_passwd."\<cr>ascii\<cr>put ".tmpfile." ".b:netrw_fname."\<esc>"
  403.    endif
  404.  
  405.    if has("win32")
  406.     exe "'z+1,.!ftp -i -n"
  407.     norm! u
  408.    else
  409.     " DON'T use <.netrc>, even though it exists
  410.     exe "'z+1,.!ftp -i -n"
  411.    endif
  412.    " save choice/id/password for future use
  413.    let b:netrw_lastfile = choice
  414.    let g:netrw_uid     = g:netrw_uid
  415.  
  416.   elseif     b:netrw_method == 4    " write with scp
  417.    exe "!scp " . tmpfile . " " . g:netrw_machine . ":" . b:netrw_fname
  418.    let b:netrw_lastfile = choice
  419.  
  420.   else " Complain
  421.    echo "***warning*** unable to comply with your request<" . choice . ">"
  422.   endif
  423.  endwhile
  424.  
  425.  " cleanup
  426. "    Decho "DBG: NetWrite: cleanup"
  427.  let result=delete(tmpfile)
  428.  if exists("b:netrw_method")
  429.   unlet b:netrw_method
  430.   unlet g:netrw_machine
  431.   unlet b:netrw_fname
  432.  endif
  433.  call s:NetOptionRestore()
  434.  
  435.  if a:firstline == 1 && a:lastline == line("$")
  436.   set nomod
  437.  endif
  438.  
  439.  " restore position
  440.  if b:netrw_col == 0
  441.   exe "norm! ".b:netrw_line."G0"
  442.  else
  443.   exe "norm! ".b:netrw_line."G0".b:netrw_col."l"
  444.  endif
  445.  
  446. "    Decho "DBG: return NetWrite }"
  447. endfunction
  448. " end of NetWrite
  449.  
  450. " ------------------------------------------------------------------------
  451.  
  452. " NetMethod:  determine method of transfer
  453. "  method == 1: rcp
  454. "         2: ftp + <.netrc>
  455. "         3: ftp + machine, id, password, and [path]filename
  456. "         4: scp
  457. "         5: http (wget)
  458. function! s:NetMethod(choice)  " globals: method machine id passwd fname
  459. "    Decho "DBG: NetMethod(a:choice<".a:choice.">) {"
  460.  
  461.  " initialization
  462.  let b:netrw_method  = 0
  463.  let g:netrw_machine = ""
  464.  let b:netrw_fname   = ""
  465.  let g:netrw_port    = ""
  466.  
  467.  " Patterns:
  468.  " mipf   : a:machine a:id password filename  Use ftp
  469.  " mf      : a:machine filename              Use ftp + <.netrc> or g:netrw_uid g:netrw_passwd
  470.  " ftpurm : ftp://host[#port]/filename          Use ftp + <.netrc> or g:netrw_uid g:netrw_passwd
  471.  " rcpurm : rcp://host/filename              Use rcp
  472.  " rcphf  : host:filename              Use rcp
  473.  " scpurm : scp://[user@]host/filename          Use scp
  474.  " httpurm: http://[user@]host/filename       Use wget
  475.  let mipf   = '\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)'
  476.  let mf     = '\(\S\+\)\s\+\(\S\+\)'
  477.  let ftpurm = 'ftp://\([^/#]\{-}\)\(#\d\+\)\=/\(.*\)$'
  478.  let rcpurm = 'rcp://\([^/]\{-}\)/\(.*\)$'
  479.  let rcphf  = '\(\I\i*\):\(\S\+\)'
  480.  let scpurm = 'scp://\([^/]\{-}\)/\(.*\)$'
  481.  let httpurm= 'http://\([^/]\{-}\)/\(.*\)$'
  482.  
  483.  " Determine Method
  484.  " rcp://hostname/...path-to-file
  485.  if match(a:choice,rcpurm) == 0
  486. "    Decho "DBG: NetMethod: rcp://..."
  487.   let b:netrw_method = 1
  488.   let g:netrw_machine= substitute(a:choice,rcpurm,'\1',"")
  489.   let b:netrw_fname  = substitute(a:choice,rcpurm,'\2',"")
  490.  
  491.  " scp://user@hostname/...path-to-file
  492.  elseif match(a:choice,scpurm) == 0
  493. "    Decho "DBG: NetMethod: scp://..."
  494.   let b:netrw_method = 4
  495.   let g:netrw_machine= substitute(a:choice,scpurm,'\1',"")
  496.   let b:netrw_fname  = substitute(a:choice,scpurm,'\2',"")
  497.  
  498.  " http://hostname/...path-to-file
  499.  elseif match(a:choice,httpurm) == 0
  500. "    Decho "DBG: NetMethod: http://..."
  501.   let b:netrw_method = 5
  502.   let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
  503.   let b:netrw_fname  = substitute(a:choice,httpurm,'\2',"")
  504.  
  505.  " ftp://hostname/...path-to-file
  506.  elseif match(a:choice,ftpurm) == 0
  507. "    Decho "DBG: NetMethod: ftp://..."
  508.   let g:netrw_machine= substitute(a:choice,ftpurm,'\1',"")
  509.   let g:netrw_port   = substitute(a:choice,ftpurm,'\2',"")
  510.   let b:netrw_fname  = substitute(a:choice,ftpurm,'\3',"")
  511.   if g:netrw_port != ""
  512.     let g:netrw_port = substitute(g:netrw_port,"#","","")
  513.   endif
  514.   if exists("g:netrw_uid") && exists("g:netrw_passwd")
  515.    let b:netrw_method = 3
  516.   else
  517.    if filereadable(expand("$HOME/.netrc"))
  518.     let b:netrw_method= 2
  519.    else
  520.     if !exists("g:netrw_uid") || g:netrw_uid == ""
  521.      call NetUserPass()
  522.     elseif !exists("g:netrw_passwd") || g:netrw_passwd == ""
  523.      call NetUserPass(g:netrw_uid)
  524.    " else just use current g:netrw_uid and g:netrw_passwd
  525.     endif
  526.     let b:netrw_method= 3
  527.    endif
  528.   endif
  529.  
  530.  " Issue an rcp: hostname:filename"
  531.  elseif match(a:choice,rcphf) == 0
  532. "    Decho "DBG: NetMethod: (rcp) host:file"
  533.   let b:netrw_method = 1
  534.   let g:netrw_machine= substitute(a:choice,rcphf,'\1',"")
  535.   let b:netrw_fname  = substitute(a:choice,rcphf,'\2',"")
  536.   if has("win32")
  537.    " don't let PCs try <.netrc>
  538.    let b:netrw_method = 3
  539.   endif
  540.  
  541.  " Issue an ftp : "machine id password [path/]filename"
  542.  elseif match(a:choice,mipf) == 0
  543. "    Decho "DBG: NetMethod: (ftp) host id pass file"
  544.   let b:netrw_method  = 3
  545.   let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
  546.   let g:netrw_uid     = substitute(a:choice,mipf,'\2',"")
  547.   let g:netrw_passwd  = substitute(a:choice,mipf,'\3',"")
  548.   let b:netrw_fname   = substitute(a:choice,mipf,'\4',"")
  549.  
  550.  " Issue an ftp: "hostname [path/]filename"
  551.  elseif match(a:choice,mf) == 0
  552. "    Decho "DBG: NetMethod: (ftp) host file"
  553.   if exists("g:netrw_uid") && exists("g:netrw_passwd")
  554.    let b:netrw_method  = 3;
  555.    let g:netrw_machine = substitute(a:choice,mf,'\1',"")
  556.    let b:netrw_fname   = substitute(a:choice,mf,'\2',"")
  557.  
  558.   elseif filereadable(expand("$HOME/.netrc"))
  559.    let b:netrw_method  = 2
  560.    let g:netrw_machine = substitute(a:choice,mf,'\1',"")
  561.    let b:netrw_fname   = substitute(a:choice,mf,'\2',"")
  562.   endif
  563.  
  564.  else
  565.   echoerr "***error*** cannot determine method"
  566.   let b:netrw_method  = -1
  567.  endif
  568.  
  569. " call Decho("DBG: NetMethod: a:choice       <".a:choice.">")
  570. " call Decho("DBG: NetMethod: b:netrw_method <".b:netrw_method.">")
  571. " call Decho("DBG: NetMethod: g:netrw_machine<".g:netrw_machine.">")
  572. " call Decho("DBG: NetMethod: g:netrw_port   <".g:netrw_port.">")
  573. " call Decho("DBG: NetMethod: g:netrw_uid    <".g:netrw_uid.">")
  574. " call Decho("DBG: NetMethod: g:netrw_passwd <".g:netrw_passwd.">")
  575. " call Decho("DBG: NetMethod: b:netrw_fname  <".b:netrw_fname.">")
  576. " call Decho("DBG: NetMethod return }")
  577. endfunction
  578. " end of NetMethod
  579.  
  580. " ------------------------------------------------------------------------
  581.  
  582. " NetUserPass: set username and password for subsequent ftp transfer
  583. "   Usage:  :call NetUserPass()            -- will prompt for userid and password
  584. "        :call NetUserPass("uid")        -- will prompt for password
  585. "        :call NetUserPass("uid","password") -- sets global userid and password
  586. function! NetUserPass(...)
  587.  
  588.  " get/set userid
  589.  if a:0 == 0
  590. "    Decho "DBG: NetUserPass(a:0<".a:0.">) {"
  591.   if !exists("g:netrw_uid") || g:netrw_uid == ""
  592.    " via prompt
  593.    let g:netrw_uid= input('Enter username: ')
  594.   endif
  595.  else    " from command line
  596. "    Decho "DBG: NetUserPass(a:1<".a:1.">) {"
  597.   let g:netrw_uid= a:1
  598.  endif
  599.  
  600.  " get password
  601.  if a:0 <= 1 " via prompt
  602. "    Decho "DBG: a:0=".a:0." case <=1:"
  603.   let g:netrw_passwd= inputsecret("Enter Password: ")
  604.  else " from command line
  605. "    Decho "DBG: a:0=".a:0." case >1: a:2<".a:2.">"
  606.   let g:netrw_passwd=a:2
  607.  endif
  608. "    Decho "DBG: return NetUserPass }"
  609. endfunction
  610. " end NetUserPass
  611.  
  612. " ------------------------------------------------------------------------
  613.  
  614. " NetOptionSave: save options and set to "standard" form
  615. function s:NetOptionSave()
  616. "    Decho "DBG: NetOptionSave()"
  617.  " Get Temporary Filename
  618.  let b:aikeep = &ai
  619.  let b:cinkeep = &cin
  620.  let b:cinokeep = &cino
  621.  let b:comkeep = &com
  622.  let b:cpokeep = &cpo
  623.  let b:twkeep = &tw
  624.  set cino =
  625.  set com  =
  626.  set cpo -=aA
  627.  set nocin noai
  628.  set tw   =0
  629.  if has("win32") && !has("win95")
  630.   let b:swfkeep= &swf
  631.   set noswf
  632. "    Decho "DBG: setting b:swfkeep to <".&swf.">"
  633.  endif
  634. endfunction
  635.  
  636. " ------------------------------------------------------------------------
  637.  
  638. " NetOptionRestore: restore options
  639. function s:NetOptionRestore()
  640. "    Decho "DBG: NetOptionRestore()"
  641.  let &ai   = b:aikeep
  642.  let &cin  = b:cinkeep
  643.  let &cino = b:cinokeep
  644.  let &com  = b:comkeep
  645.  let &cpo  = b:cpokeep
  646.  let &tw   = b:twkeep
  647.  if exists("b:dirkeep")
  648.   let &swf= b:swfkeep
  649.   unlet b:swfkeep
  650.  endif
  651.  unlet b:aikeep
  652.  unlet b:cinkeep
  653.  unlet b:cinokeep
  654.  unlet b:comkeep
  655.  unlet b:cpokeep
  656.  unlet b:twkeep
  657. endfunction
  658.  
  659. " ------------------------------------------------------------------------
  660.  
  661. " Restore
  662. let &cpo= s:save_cpo
  663. unlet s:save_cpo
  664. " vim:ts=8
  665.